package com.example.user.myzzyl_android;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.sunfusheng.marqueeview.MarqueeView;

import java.util.List;

/**
 * Created by User on 2017/7/19.
 */

public class ZhuYeMianAdpter extends BaseAdapter {
    Context context;
    List<String> list;
    ConvenientBanner convenientBanner;
    List<String> data;
    List<String> title;
    MarqueeView marqueeView;
    Intent intent = new Intent();
    List<String> Id;


    public ZhuYeMianAdpter(Context context, List<String> list, List<String> data, List<String> title,List<String> Id) {
        this.context = context;
        this.list = list;
        this.data = data;
        this.title = title;
        this.Id=Id;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        if (i == 0) {
            view = View.inflate(context, R.layout.item1, null);
            convenientBanner = view.findViewById(R.id.ConvenientBanner);
            convenientBanner.setPages(new CBViewHolderCreator() {
                @Override
                public Object createHolder() {
                    return new LocalImageHolderView();
                }
            }, data).setPageIndicator(new int[]{R.mipmap.oval, R.mipmap.oval1});
        } else if (i == 1) {
            view = View.inflate(context, R.layout.item2, null);
            marqueeView = view.findViewById(R.id.MarqueeView);
            marqueeView.startWithList(title);
            marqueeView.setOnItemClickListener(new MarqueeView.OnItemClickListener() {
                @Override
                public void onItemClick(int position, TextView textView) {
                    intent.putExtra("url","http://zhihui.expo2017.net.cn/zzwhe/zzwhe/ybzx/details?id="+ Id.get(position));
                    context.startActivity(intent.setClass(context,XiangQing.class));
                }
            });
        } else if (i == 2) {
            view = View.inflate(context, R.layout.item3, null);
            ImageView imageView = view.findViewById(R.id.image1);
            ImageView imageView2 = view.findViewById(R.id.image2);
            ImageView imageView3 = view.findViewById(R.id.image3);
            ImageView imageView4 = view.findViewById(R.id.image4);
            ImageView imageView5 = view.findViewById(R.id.image5);
            ImageView imageView6 = view.findViewById(R.id.image6);
            ImageView imageView7 = view.findViewById(R.id.image7);
            ImageView imageView8 = view.findViewById(R.id.image8);
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    intent.putExtra("url","http://zhihui.expo2017.net.cn/zz/changguanfenlei.html");
                    context.startActivity(intent.setClass(context,XiangQing.class));
                }
            });
            imageView2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    intent.putExtra("url","http://zhihui.expo2017.net.cn/zz/yuanbodongtai.html");
                    context.startActivity(intent.setClass(context,XiangQing.class));
                }
            });
            imageView3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(context, "功能开发中，尽请期待。", Toast.LENGTH_SHORT).show();
                }
            });
            imageView4.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    context.startActivity(intent.setClass(context,ShoopingActivity.class));
                }
            });
            imageView5.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    intent.putExtra("url","http://zhihui.expo2017.net.cn/zz/zhiwubaikelei.html");
                    context.startActivity(intent.setClass(context,XiangQing.class));
                }
            });
            imageView6.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    context.startActivity(intent.setClass(context,XianLuActivity.class));
                }
            });
            imageView7.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    context.startActivity(intent.setClass(context,TingCheActivity.class));
                }
            });
            imageView8.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    intent.putExtra("url","http://zhihui.expo2017.net.cn/zz/yijiantousu.html");
                    context.startActivity(intent.setClass(context,XiangQing.class));
                }
            });
        } else if (i == 3) {
            view = View.inflate(context, R.layout.item4, null);
        }
        return view;
    }



    private class LocalImageHolderView implements Holder<String> {
        private SimpleDraweeView imageView;

        @Override
        public View createView(Context context) {
            imageView = (SimpleDraweeView) View.inflate(context, R.layout.imageitem, null);
            return imageView;
        }

        @Override
        public void UpdateUI(Context context, int position, String data) {
            imageView.setImageURI(data);
        }
    }
}
